package com.xugongzhang.unsafeDemo;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author X
 * @date 2022/7/23 10:01
 */
public class UnsafeTest {
    public static void main(String[] args) {

        AtomicReference<User> atomicReference = new AtomicReference<>();
        User z3 = new User("Z3", 33);
        User l4 = new User("l4", 25);
        atomicReference.set(z3);
        System.out.println(atomicReference.compareAndSet(z3, l4));
        System.out.println(atomicReference.get().toString());
    }
}

@Getter
@ToString
@Setter
@NoArgsConstructor
@AllArgsConstructor
class User {
    public String username;
    int age;
}
